package com.yoomiito.app.ui.my;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.yoomiito.app.R;
import com.yoomiito.app.adapter.my.MyBondAdapter;
import com.yoomiito.app.adapter.my.MyTeamSaleAdapter;
import com.yoomiito.app.base.App;
import com.yoomiito.app.base.BaseActivity;
import com.yoomiito.app.model.bean.MyTeamSaleInfo;
import com.yoomiito.app.model.my.BondInfo;
import com.yoomiito.app.present.my.activity.MyBondDetailPresenter;
import com.yoomiito.app.present.my.activity.MyTeamSalePresenter;
import com.yoomiito.app.utils.DateUtils;
import com.yoomiito.app.widget.wheelview.DateSelectDialog;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class MyBondDetailActivity extends BaseActivity<MyBondDetailPresenter> {

    private View empty;
    @BindView(R.id.rcy)
    RecyclerView recyclerView;

    @BindView(R.id.smartRefreshLayout)
    SmartRefreshLayout smartRefreshLayout;

    private MyBondAdapter mAdapter;
    private int page = 1;


    @Override
    public int getLayoutId() {
        return R.layout.activity_my_bond;
    }

    @Override
    public MyBondDetailPresenter newP() {
        return new MyBondDetailPresenter(App.mAppConfig);
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        super.initData(savedInstanceState);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        mAdapter = new MyBondAdapter();
        recyclerView.setAdapter(mAdapter);
        empty = LayoutInflater.from(context).inflate(R.layout.item_live_empty, null, false);
        getP().getBondList(page);
        smartRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                page = 1;
                getP().getBondList(page);
            }
        });
        smartRefreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                page++;
                getP().getBondList(page);
            }
        });
    }


    public void setData(List<BondInfo>  data){
        if (page == 1) {
            if (data == null || data.size() <= 0) {
                mAdapter.setNewData(null);
                mAdapter.setEmptyView(empty);
            } else {
                mAdapter.setNewData(data);
            }
            smartRefreshLayout.setNoMoreData(false);
        } else {
            smartRefreshLayout.finishLoadMore(true);
            if (data == null || data.size() <= 0) {
                Toast.makeText(context, "没有更多了", Toast.LENGTH_SHORT).show();
                smartRefreshLayout.finishLoadMoreWithNoMoreData();
            } else {
                mAdapter.addData(data);
            }
        }
        smartRefreshLayout.finishRefresh();
        smartRefreshLayout.finishLoadMore();
    }
}
